package com.xd.user.api.entity;

import cn.hutool.json.JSON;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.annotation.TableName;
import com.xd.common.base.BaseModel;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.Map;

/**
 * @author Exrickx
 */
@Data
@Entity
@Table(name = "xd_log")
@TableName("xd_log")
@ApiModel(value = "日志")
@org.hibernate.annotations.Table(appliesTo = "xd_log",comment = "日志")
public class Log extends BaseModel<Log> {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "方法操作名称")
    @Column( columnDefinition = "varchar(100) default '' comment '方法操作名称'")
    private String name;

    @ApiModelProperty(value = "日志类型 0登陆日志 1操作日志")
    @Column( columnDefinition = "tinyint(2) default 1 comment '日志类型 0登陆日志 1操作日志'")
    private Integer logType;

    @ApiModelProperty(value = "请求路径")
    @Column( columnDefinition = "varchar(500) default '' comment '请求路径'")
    private String requestUrl;

    @ApiModelProperty(value = "请求类型")
    @Column(columnDefinition = "varchar(20) default '' comment '请求类型'")
    private String requestType;

    @ApiModelProperty(value = "请求参数")
    @Column( columnDefinition = "varchar(1000) default '' comment '请求参数'")
    private String requestParam;

    @ApiModelProperty(value = "请求用户")
    @Column( columnDefinition = "varchar(100) default '' comment '请求用户'")
    private String username;

    @ApiModelProperty(value = "ip")
    @Column( columnDefinition = "varchar(100) default '' comment 'ip'")
    private String ip;

    @ApiModelProperty(value = "ip信息")
    @Column( columnDefinition = "varchar(255) default '' comment 'ip信息'")
    private String ipInfo;

    @ApiModelProperty(value = "花费时间")
    @Column( columnDefinition = "bigint  comment '花费时间'")
    private Long costTime;

    /**
     * 转换请求参数为Json
     * @param paramMap
     */
    public void setMapToParams(Map<String, String[]> paramMap) {
        this.requestParam = JSONUtil.toJsonStr(paramMap);
    }

}
